﻿#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

#include "DoseStat.h"

namespace py = pybind11;

// 定义Python模块
PYBIND11_MODULE(dose_statistics_py, m)
{
    m.doc() = "Dose Statistics Python Bindings";

    // 绑定DoseStatisticsResult结构体
    py::class_<dosestat::DoseStatRet>(m, "DoseStatisticsResult")
        .def(py::init<>())
        .def_readwrite("binned_dose_values", &dosestat::DoseStatRet::binnedDoseValues)
        .def_readwrite("accumulated_relative_volumes", &dosestat::DoseStatRet::accumulatedRelativeVolumes)
        .def("__repr__",
             [](const dosestat::DoseStatRet& self) { return "DoseStatisticsResult(binned_dose_values=[...], accumulated_relative_volumes=[...])"; });

    // 绑定accumulate函数
    m.def("accumulate", &dosestat::Accumulate, py::arg("voxel_volume"), py::arg("voxel_dose"), py::arg("do_exact_accumulation") = false,
          "计算DVH(剂量体积直方图)");

    // 绑定get_dose_statistics_roi_interp函数
    m.def("get_dose_statistics_roi_interp", &dosestat::GetDoseStatRoiInterp, py::arg("dose_type"), py::arg("binned_dose_values"),
          py::arg("accumulated_relative_volumes"), py::arg("voxel_volume"), py::arg("voxel_dose"), py::arg("dose_at_volume") = 0.0,
          "计算ROI内的剂量统计指标");

    // 绑定get_metric函数
    m.def("get_metric", &dosestat::GetMetric, py::arg("dose_at_volume"), py::arg("binned_dose_values"), py::arg("accumulated_relative_volumes"),
          "辅助函数: 获取特定体积百分比对应的剂量");
}